package com.neuedu.his.controller;


import com.neuedu.his.po.Medicalrecord;
import com.neuedu.his.service.MedicalrecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/medicalrecord")
public class MedicalRecordController {

    @Resource
    private MedicalrecordService medicalRecordService;

    // 新增病历
    @PostMapping("/add")
    public String add(@RequestBody Medicalrecord record) {
        int result = medicalRecordService.insert(record);
        if (result > 0) return "新增成功";
        else return "新增失败";
    }

    // 更新病历
    @PutMapping("/update")
    public String update(@RequestBody Medicalrecord record) {
        int result = medicalRecordService.update(record);
        if (result > 0) return "更新成功";
        else return "更新失败";
    }

    // 删除病历
    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable Integer id) {
        int result = medicalRecordService.deleteById(id);
        if (result > 0) return "删除成功";
        else return "删除失败";
    }

    // 根据ID查询病历
    @GetMapping("/{id}")
    public Medicalrecord getById(@PathVariable Integer id) {
        return medicalRecordService.getById(id);
    }

    // 查询所有病历
    @GetMapping("/list")
    public List<Medicalrecord> getAll() {
        return medicalRecordService.getAll();
    }
}
